package com.xuelang.pipeline.artifact.app.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.config.HarborV2FeignConfig;
import com.xuelang.pipeline.artifact.app.harborv2.fallback.UserServiceFallbackFactory;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateHarborUserRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.SearchUserQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.SearchUserResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 封装Docker v2.11.0-70255684以上用户相关接口-对应user
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@FeignClient(
        name = "user-service",
        url = "${feign.rpc.harborV2Service}",
        configuration = HarborV2FeignConfig.class,
        fallbackFactory = UserServiceFallbackFactory.class)
public interface UserService {

    /**
     * 创建用户
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/users", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createUser(@RequestBody @Valid CreateHarborUserRequest request);

    /**
     * 刪除用户
     *
     * @param userId
     * @return
     */
    @DeleteMapping(value = "/users/{user_id}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteUser(@PathVariable("user_id") Long userId);

    /**
     * 通过userName获取用户信息
     *
     * @param query
     * @return
     */
    @GetMapping(value = "/users/search", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<SearchUserResponse>> searchUserByUserName(@SpringQueryMap SearchUserQuery query);

    /**
     * 删除用户
     *
     * @param userId
     * @return
     */
    @DeleteMapping(value = "/users/{user_id}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteRepositoryOfAnyFormat(@PathVariable("user_id") String userId);


}
